package com.online.teaching.module.common.resource.utils;
import com.online.teaching.module.common.resource.domain.vo.GetDirectoryVO;
import sun.reflect.generics.tree.Tree;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
 * @ClassName : MenuTreeUtil  //类名
 * @Description :   //描述
 * @Author : YG  //作者
 * @Date: 2020-11-26 18:45  //时间
 */

public class MenuTreeUtil {

    public static Map<String,Object> mapArray = new LinkedHashMap<String, Object>();
    public List<GetDirectoryVO> menuCommon;
    public List<Object> list = new ArrayList<Object>();

    public List<Object> menuList(List<GetDirectoryVO> menu){ //controller层调用的方法   ，并将数据以list的形式返回
        this.menuCommon = menu;
        for (GetDirectoryVO x : menu) {
            Map<String,Object> mapArr = new LinkedHashMap<String, Object>();
            if(x.getIsParent().equals(1)){ //判断是否为父极
                mapArr.put("fileId", x.getFileId());
                mapArr.put("fileName", x.getFileName());
                mapArr.put("parentId", x.getParentId());
                mapArr.put("isParent", x.getIsParent());
                mapArr.put("teachesId", x.getTeachesId());

                mapArr.put("child", menuChild(x.getFileId()));  //去子集查找遍历
                list.add(mapArr);
            }
        }
        return list;
    }

    public List<?> menuChild(Integer id){ //子集查找遍历
        List<Object> lists = new ArrayList<Object>();
        for(GetDirectoryVO a:menuCommon){
            Map<String,Object> childArray = new LinkedHashMap<String, Object>();
            if(a.getParentId().equals(id) ){
                childArray.put("fileId", a.getFileId());
                childArray.put("fileName", a.getFileName());
                childArray.put("parentId", a.getParentId());
                childArray.put("isParent", a.getIsParent());
                childArray.put("teachesId", a.getTeachesId());
                childArray.put("child", menuChild(a.getFileId()));
                lists.add(childArray);
            }
        }
        return lists;
    }

}
